using System;
using L=Science.Physics.GeneralPhysics;

namespace Serway.Chapter08
{
	/// <summary>
	/// Example09: Block-Spring Collision
	/// A block having a mass of 0.80 kg is given an initial 
	/// velocity  = 1.2 m/s to the right and collides with a 
	/// spring of negligible mass and force constant k=50 N/m, 
	/// as shown in Figure 8.14.
	/// (A) Assuming the surface to be frictionless, calculate 
	/// the maximum compression of the spring after the collision.
	/// x_{max} = 0.15 m
	/// (B) Suppose a constant force of kinetic friction acts 
	/// between the block and the surface, with  \mu_k = 0.50. 
	/// If the speed of the block at the moment it collides 
	/// with the spring is  v_A = 1.2 m/s, what is the maximum 
	/// compression in the spring?
	/// x_c = 0.092 m
	/// </summary>
	public class Example09
	{
		public Example09()
		{
		}
		private string result;
		public string Result
		{
			get{return result;}
		}
		public void Compute()
		{
			L.Mass m = new L.Mass();
			m.kg = 0.8;
			L.Velocity vi = new L.Velocity();
			vi.X = 1.2;
			double k = 50.0;
			double mu = 0.5;
			//(A)
			L.KineticEnergy K = new L.KineticEnergy(m,vi);
			double xmax = Math.Sqrt(2.0*K.J/k);
			result+=Convert.ToString(xmax);
			//(B)
            Science.Mathematics.Calculus.PolynomialFunction f = new Science.Mathematics.Calculus.PolynomialFunction();
			f.MaximumPower = 2;
			f.Which = 0;
			f.Coefficient = -K.J;
			f.Which = 1;
			f.Coefficient = mu*m.kg*L.Constant.AccelerationOfGravity;
			f.Which = 2;
			f.Coefficient = 0.5*k;
			f.FindRoot();
         	result+="\r\n"+Convert.ToString(f.Root[0].Real);
			result+="\r\n"+Convert.ToString(f.Root[1].Real);
		}
	}
}
